﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using cash_desk_model;
using cash_desk_model.src.model;
using cash_desk_model.src.security;

namespace cash_desk
{
    public partial class AddOrDeleteUserForm : Form
    {
        public AddOrDeleteUserForm()
        {
            InitializeComponent();
        }

        private void registerButton_Click(object sender, EventArgs e)
        {
            SecurityService.SetupDBConn();
            SecurityService service = new SecurityService();
            if (this.userNameTextBox.Text.Length > 0 && this.userFullNameTextBox.Text.Length > 0 &&
                this.userAddressTextBox.Text.Length > 0 && this.userPasswordTextBox.Text.Trim().Equals(
                this.confirmPasswordTextBox.Text.Trim()))
            {
                if (service.SaveNewUser(this.userNameTextBox.Text, this.userFullNameTextBox.Text,
                    this.userEmailTextBox.Text, this.userAddressTextBox.Text, this.userStatusComboBox.SelectedItem.ToString(),
                    this.userPasswordTextBox.Text) == 0)
                {
                    SecurityService.SetPassword(this.userNameTextBox.Text, this.userPasswordTextBox.Text);
                    this.registrationComplatedLabel.Visible = true;
                }
            }
            SecurityService.DestroyDBConn();
        }
    }
}
